function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {
    $(".pass_info").submit(function (e) {
        e.preventDefault();
        // alert(3333)
        // TODO 修改密码
        //准备参数
        var old_password = $("#old_password").val()
        var new_password = $("#new_password").val()
        var new_password2 = $("#new_password2").val()

        if (old_password == new_password){
            alert("新密码不能和旧密码一致");
            return;
        }

        if (new_password != new_password2){
            alert("确认密码必须跟新密码一致");
            return;
        }
        // 封装参数
        var params = {
            old_password: old_password,
            new_password: new_password
        }

        $.ajax({
            url: "/user/change_password",
            method: "POST",
            contentType: "application/json",
            data: JSON.stringify(params),
            dataType: "json",
            headers:{
                "X-CSRFToken": getCookie('csrf_token')
            },
            success: function (ret) {
                //判断是否修改成功
                if (ret.errno==0){
                    // 提示修改成功，并刷新页面
                    alert(ret.errmsg)
                    window.location.reload()
                }else {
                    alert(ret.errmsg)
                }
            }

        })


    })
})